from marshmallow import Schema
from flask_restplus import Namespace, fields
from app.models.user import User


class UserSchemas(object):
    def __init__(self, namespace):
        self.namespace = namespace

    def user_list_query(self):
        return {
            "page": "page",
            "per_page": "per_page",
            "username": "username",
            "order_id": "order_id",
            "email": "email",
            "vipuser": "vipuser",
            "superuser": "superuser",
        }

    def user_order_body(self):
        return self.namespace.model(
            "user_order_body",
            {
                "order_id": fields.String(),
                "title": fields.String(),
                "ticket_code": fields.String(),
                "check_code": fields.String(),
                "pirce": fields.String(),
                "cinema": fields.String(),
                "create_date": fields.DateTime(),
            },
        )

    def user_info_body(self):
        return self.namespace.model(
            "user_info",
            {
                "id": fields.Integer(),
                "username": fields.String(),
                "email": fields.String(),
                "activation": fields.Boolean(),
                "superuser": fields.Boolean(),
                "vipuser": fields.Boolean(),
                "orders": fields.List(fields.Nested(self.user_order_body())),
            },
        )

    def user_list_body(self):
        return self.namespace.model(
            "user_list_body",
            {"total": fields.Integer(), "data": fields.List(fields.Nested(self.user_info_body()))},
        )

    def user_registr_query(self):
        return self.namespace.model(
            "user_registr",
            {
                "username": fields.String(max_length=256, required=True),
                "password": fields.String(max_length=256, required=True),
                "password2": fields.String(max_length=256, required=True),
                "email": fields.String(max_length=256, default=""),
                "activation": fields.Boolean(default=True),
            },
        )

    def user_registr_body(self):
        return self.namespace.model("user_body", {"id": fields.Integer()})
